package com.starlink.model.dtomapper;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.starlink.model.domain.StarPaintDO;
import com.starlink.model.request.StarPaintRequest;
import com.starlink.model.vo.StarPaintVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.Optional;

/**
 * @author zhanghong
 */
@Mapper(componentModel = "spring", imports = {JSON.class, Optional.class, Lists.class})
public interface StarPaintDtoMapper {

    StarPaintDtoMapper INSTANCE = Mappers.getMapper(StarPaintDtoMapper.class);

    /**
    * DO to VO
    * @param starPaintDO
    * @return
    */
//    @Mappings({
//            @Mapping(target = "detailImg", expression = "java(Optional.ofNullable(starPaintDO.getDetailImg()).map(item -> JSON.parseArray(item, String.class)).orElse(Lists.newArrayList()))"),
//    })
    StarPaintVO do2VO(StarPaintDO starPaintDO);

    /**
     * request to DO
     * @param request
     * @return
     */
//    @Mappings({
//            @Mapping(target = "detailImg", expression = "java(Optional.ofNullable(request.getDetailImg()).map(JSON::toJSONString).orElse(null))"),
//    })
    StarPaintDO request2DO(StarPaintRequest request);
}
